package com.ayq.activiti.common.util;

/**
 * 自定义返回码
 *
 * @author admin
 */
public enum ResCode {
  /** 成功 */
  FAIL(0, "失败"),
  OK(1, "成功"),
  ALERT(2, "提醒"),
  Exception(3, "服务异常，请联系管理员！"),

  /** 成功 */
  INTERNAL_CODE_SUCCESS(1, "成功"),
  INTERNAL_CODE_FAIL(0, "失败"),
  SQL_SELECT_EXIST(101, "查询数据对象已存在"),
  SQL_SELECT_NOT_EXIST(102, "查询数据对象不存在或数量<1"),
  SQL_UPDATE_FAIL(103, "数据对象更新失败"),
  PARAMETER_ERROR(400, "参数错误:"),
  PARAMETER_ERROR_TO_INT(402, "参数转换错误：不能转换为Integer对象"),
  PARAMETER_ERROR_TO_LONG(403, "参数转换错误：不能转换为Long对象"),
  PARAMETER_ERROR_TO_BOOLEAN(404, "参数转换错误：不能转换为Boolean对象"),
  PARAMETER_ERROR_TO_DATE(405, "参数转换错误：不能转换为Date对象"),
  OBJECT_EXIST(406, "不能添加重复数据！"),
  OBJECT_NOT_EXIST(407, "操作对象不存在！"),
  OBJECT_CONVERSION_EXCEPTION(408, "对象转换异常"),
  STRING_IS_NULL(410, "空字符串"),
  LONG_IS_NULL(411, "空LONG"),
  OBJECT_CAN_NOT_NULL(411, "不能为空"),

  PARAMETER_CAN_NOT_NULL_ID(412, "id不能为空"),
  PARAMETER_CAN_NOT_NULL_USERNAME(413, "姓名不能为空"),
  PARAMETER_CAN_NOT_NULL_ACCOUNT(414, "账号不能为空"),
  PARAMETER_CAN_NOT_NULL_ORG_NAME(415, "企业名称不能为空"),
  PARAMETER_CAN_NOT_NULL_ID_CARD_NO(416, "身份证号码不能为空"),


  /** oauth2返回码 */
  INVALID_TOKEN(2000, "invalid_token"),
  INVALID_SCOPE(2001, "invalid_scope"),
  INVALID_REQUEST(2002, "invalid_request"),
  INVALID_CLIENT(2003, "invalid_client"),
  INVALID_GRANT(2004, "invalid_grant"),
  REDIRECT_URI_MISMATCH(2005, "redirect_uri_mismatch"),
  UNAUTHORIZED_CLIENT(2006, "unauthorized_client"),
  EXPIRED_TOKEN(2007, "expired_token"),
  UNSUPPORTED_GRANT_TYPE(2008, "unsupported_grant_type"),
  UNSUPPORTED_RESPONSE_TYPE(2009, "unsupported_response_type"),
  UNAUTHORIZED(2012, "unauthorized"),
  SIGNATURE_DENIED(2013, "signature_denied"),

  ACCESS_DENIED(4030, "access_denied"),
  ACCESS_DENIED_BLACK_LIMITED(4031, "access_denied_black_limited"),
  ACCESS_DENIED_WHITE_LIMITED(4032, "access_denied_white_limited"),
  ACCESS_DENIED_AUTHORITY_EXPIRED(4033, "access_denied_authority_expired"),
  ACCESS_DENIED_UPDATING(4034, "access_denied_updating"),
  ACCESS_DENIED_DISABLED(4035, "access_denied_disabled"),
  ACCESS_DENIED_NOT_OPEN(4036, "access_denied_not_open"),

  /* -------------业务错误--------------- */
  BUSINESS_STATE_ERROR(30000, "业务状态错误"),


  /** 301-账号相关 */
  ACCOUNT_NOT_EXIST(30100, "账号不存在"),
  ACCOUNT_DISABLED(30101, "账号已禁用"),
  ACCOUNT_EXPIRED(30102, "账号过期"),
  ACCOUNT_LOCKED(30103, "账号被锁定"),
  ACCOUNT_EXIST(30104, "账号已存在"),
  ACCOUNT_CAN_NOT_BE_NULL(30105, "账号不能为空"),
  ACCOUNT_FORMAT_ERROR(30106, "账号格式错误"),
  ACCOUNT_INCORRECT(30107, "输入账号有误"),
  ACCOUNT_ID_NOT_EXIST(30108, "账号ID不存在"),
  ACCOUNT_NOT_LOGIN(30109, "账号未登录"),



  ACCOUNT_CONFIG_FAIL_UID(30109, "保存账号配置失败：UID"),

  REGISTER_FAIL(30110, "注册失败"),

  ACCOUNT_OR_PASSWORD_ERROR(30201, "账号或密码错误"),
  PASSWORD_ERROR(30202, "密码错误"),
  SALT_ERROR(302023, "盐加密错误"),
  SECRET_KEY_GENERATION_ERROR(30204, "秘钥生成错误"),
  VERIFICATION_CODE_OR_OLD_PASSWORD_CAN_NOT_BE_NULL(30205, "原密码或验证码不能同时为空"),
  OLD_PASSWORD_CAN_NOT_BE_NULL(30206, "原密码不能为空！"),

  ACCOUNT_CONFIG_NOT_EXIST(30300, "账号配置不存在"),

  UID_EXIST(30500, "识别码已存在,对象无需注册"),
  UID_NOT_EXIST(30501, "识别码不存在,检查异常原因！"),
  UID_CAN_NOT_BE_NULL(30501, "识别码不能为空！检查异常原因！"),

  ROLE_NOT_EXIST(30600, "角色不存在"),
  ROLE_EXIST(30601, "角色已存在"),
  ROLE_USE(30601, "角色使用中，请先删除使用者！"),

  /**31-用户*/
  USER_NOT_EXIST(31001, "用户不存在"),
  USER_EXIST(31002, "用户已存在"),
  USER_INFO_ERROR(31005, "姓名/身份证/电话信息有误"),
  PHONE_IS_NULL(31003, "手机号为空"),
  USER_NAME_DO_NOT_MATCH(31004, "请核对用户姓名是否正确"),

  LEGAL_NEED_REAL_NAME_AUTH(31015, "请先完成法人实名认证"),


  ID_CARD_INCORRECT_FORMAT(31007, "身份证格式错误"),


  USER_STATE_IS_CONSISTENT(31008, "用户状态与提交状态一致"),

  USER_NAME_OR_ID_CARD_AUDIT_ERROR(31101, "姓名或身份证认证失败"),
  LEGAL_NAME_OR_ID_CARD_AUDIT_ERROR(31102, "法人身份证认证失败"),
  USER_CERTIFIED(31104, "用户已认证"),

  MOBILE_PHONE_INCORRECT_FORMAT(31201, "手机号码格式有误！"),
  PHONE_INCORRECT_FORMAT(31202, "座机号码格式有误！"),
  PHONE_OR_MOBILE_INCORRECT_FORMAT(31203, "手机或座机号码格式有误！"),

  /**32-公司相关*/
  ORGANIZATION_NOT_EXIST(32001, "企业不存在"),
  ORGANIZATION_EXIST(32002, "企业已存在"),
  ORGANIZATION_ID_NULL(32003, "企业id为空"),
  ORGANIZATION_AUDIT_ERROR(32004, "企业认证失败"),
  ORGANIZATION_CAN_NOT_DELETE(32005, "企业不允许被删除"),
  ORGANIZATION_LEGAL_IS_NOT_CONSISTENT(32006, "企业不允许被删除"),
  ORGANIZATION_STATUS_EXCEPTION(32007, "企业状态异常"),
  ORGANIZATION_NOT_EXIST_BUT_TYPE_ERROR(32008, "企业不存在（状态错误）"),

  ORGANIZATION_NAME_CAN_NOT_NULL(32009, "企业名称不能为空"),

  ORGANIZATION_GET_FAIL(32001, "获取企业信息失败"),




  ORGANIZATION_USER_BINDING_EXISTS(32101, "企业用户绑定关系已存在"),
  ORGANIZATION_USER_BINDING_NOT_EXISTS(32102, "企业用户绑定关系不存在"),

  ORGANIZATION_CERT_NOT_EXISTS(32201, "企业认证信息不存在"),
  //企业认证信息已存在
  ORGANIZATION_CERT_EXISTS(32202, "企业已认证"),
  ORGANIZATION_CERT_EXCEPTION(32203, "企业认证数据异常"),
  ORGANIZATION_CERT_FAIL_NULL(32204, "企业认证失败：空数据"),

  /**33-财务financial*/
  FINANCIAL_BILL_IS_NOT_EXIST(330020,"账单不存在"),

  FINANCIAL_ACCOUNT_WALLET_IS_NOT_EXIST(33101, "小金库不存在"),
  FINANCIAL_ACCOUNT_WALLET_LACK_OF_BALANCE(33102, "小金库余额不足"),

  /**34-商品*/
  GOODS_NOT_EXIST(34001, "商品不存在"),
  SOME_GOODS_NOT_EXIST(34002, "部分商品不存在"),
  GOODS_STOCK_INSUFFICIENT(34002, "商品存量不足"),
  GOODS_ORDER_NUMBER_ERROR(34003, "商品下单数量错误"),

  /**35-订单*/
  ORDER_NOT_EXIST(35001, "订单不存在"),
  ORDER_STATE_NO_NEED_PAY(35002, "订单不是待支付状态"),
  ORDER_STATE_ALREADY_PAID(35002, "订单已完成"),
  ORDER_STATE_CANCEL(35003, "订单已取消"),
  ORDER_STATE_PARTIAL_CANCELLATION(35004, "订单部分取消"),

  /**36-合同与签约*/
  UNSIGNED_CONTRACT_CANNOT_BE_CERTIFIED(36001, "未完成签约的合同不能出证"),




  /**39-安全相关、短信、第三方*/
  CREDENTIALS_EXPIRED(39001, "证书过期"),
  BAD_CREDENTIALS(39002, "凭证错误"),

  VERIFICATION_CODE_NOT_CREATE(39101, "短信验证码未生成"),
  VERIFICATION_CODE_IS_NULL(39102, "验证码为空"),
  VERIFICATION_CODE_DOSE_NOT_MATCH(39103, "验证码不匹配"),




  /** 请求错误 */
  BAD_REQUEST(40000, "bad_request"),
  NOT_FOUND(40004, "not_found"),
  METHOD_NOT_ALLOWED(40005, "method_not_allowed"),
  MEDIA_TYPE_NOT_ACCEPTABLE(40006, "media_type_not_acceptable"),
  TOO_MANY_REQUESTS(40209, "too_many_requests"),

  FILE_FLOW_EXCEPTION(45000, "文件流异常"),
  UPLOAD_FAIL(45001, "上传失败"),


  NOT_NUMBER(41000, "输入字段不是数字"),

  /** 系统错误 */
  ERROR(50000, "ERROR"),
  GATEWAY_TIMEOUT(50004, "gateway_timeout"),
  SERVICE_UNAVAILABLE(50003, "service_unavailable");

  private int code;
  private String message;

  ResCode() {}

  ResCode(int code, String message) {
    this.code = code;
    this.message = message;
  }

  public static ResCode getResultEnum(int code) {
    for (ResCode type : ResCode.values()) {
      if (type.getCode() == code) {
        return type;
      }
    }
    return ERROR;
  }

  public static ResCode getResultEnum(String message) {
    for (ResCode type : ResCode.values()) {
      if (type.getMessage().equals(message)) {
        return type;
      }
    }
    return ERROR;
  }

  public int getCode() {
    return code;
  }

  public String getMessage() {
    return message;
  }
}
